package cn.qidisoft.edu.hzjt.service.xb.impl;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.xb.PartyInfomationMapper;
import cn.qidisoft.edu.hzjt.model.xb.PartyInfomationEn;
import cn.qidisoft.edu.hzjt.service.xb.IPartyInfomationService;
import cn.qidisoft.edu.hzjt.utils.LogType;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PartyInfomationServiceImpl implements IPartyInfomationService {

	protected static final LoggerAdapter LOGGER = LoggerAdapterFactory
			.getLogger(LogType.HZJT_LOGGER.val);

	@Autowired
	private PartyInfomationMapper mapper;

	@Override
	public List<PartyInfomationEn> queryList(PartyInfomationEn partyInfomationEn) {
		return mapper.queryList(partyInfomationEn);
	}

	@Override
	public PaginationBean<PartyInfomationEn> queryPageList(PartyInfomationEn partyInfomationEn, Page page) {
		try {
			int totalRecords = mapper.queryPageListcount(partyInfomationEn);
			
			 PaginationBean<PartyInfomationEn> pageHolder = new PaginationBean<>(page, totalRecords);
	            List<PartyInfomationEn> resultList = mapper
	                    .queryPageList(partyInfomationEn,
	                            new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
	                                    pageHolder.getPageSize()));
	            pageHolder.setPageList(resultList);
	            return pageHolder;
		} catch (Exception e) {
			LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                    this.getClass().getName(),
                    ToStringBuilder.reflectionToString(partyInfomationEn, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                    e);
		}
	}

	@Override
	public PartyInfomationEn queryByPK(PartyInfomationEn partyInfomationEn) {
		return mapper.queryByPK(partyInfomationEn);
	}

	@Override
	public int insert(PartyInfomationEn partyInfomationEn) {
		return mapper.insert(partyInfomationEn);
	}

	@Override
	public int update(PartyInfomationEn partyInfomationEn) {
		mapper.update(partyInfomationEn);
		return 0;
	}

	@Override
	public int delete(PartyInfomationEn partyInfomationEn) {
		mapper.delete(partyInfomationEn);
		return 0;
	}

	public PartyInfomationEn getBydangjianId(Integer infoId) {
		return  mapper.getBydangjianId(infoId);
	}

}
